﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArbolandiaBL
{
    internal class UIAdvancedSearch
    {
        private ArbolandiaDBDataContext _db;
        public UIAdvancedSearch()
        {
            _db = new ArbolandiaDBDataContext();
        }
        internal List<UIProductResume> GetAdvancedSearch(string p1, decimal p2_1, decimal p2_2, string p3, string p4, string p5, string p6, string p7, string p8)
        {
            var res = new List<UIProductResume>();
            var query = from p in _db.spAdvancedSearch(p1, p2_1, p2_2, p3, p4, p5, p6, p7, p8)
                        select p;
            foreach (var item in query)
            {

                var uiprod = new UIProductResume();
                uiprod.Id = item.Id;
                uiprod.ImageUrl = item.ImageUrl;
                uiprod.LowerPrice = item.LowerPrice;
                uiprod.Name = item.Name;
                uiprod.ShortDescription = item.ShortDescription;

                var listPreferences = from p in _db.spGetProductPreferences(item.Id)
                                      select new
                                      {
                                          Name = p.Name,
                                          Description = p.Description,
                                          Order = p.Order,
                                          ImageUrl = p.url
                                      };
                uiprod.ProductPreferences = new List<UIProductPreference>();
                foreach (var p in listPreferences)
                {
                    uiprod.ProductPreferences.Add(new UIProductPreference()
                    {
                        Name = p.Name,
                        Description = p.Description,
                        Order = (short)p.Order,
                        ImageUrl = p.ImageUrl
                    });
                }
                res.Add(uiprod);
            }
            return res;
        }
    }
}
